<template>
  <div>
    <h1>post form表单请求</h1>
    <br/>
    <button @click="post">点击请求数据</button>
    <hr/>
    <div>
      数据：{{info}}
    </div>
  </div>
</template>

<script>
import axios from "axios";

export default {
  name: 'post-form',
  data(){
    return{
      info: null
    }
  },
  methods:{
    post(){
      let formData = new FormData();
      //参数
      formData.append("param1", 22);
      formData.append("param2", "12345");
      formData.append("param3", 13.22);
      formData.append("param4", '2022-09-09 12:12:12');
      axios
        .post('http://localhost:9700/test/post/form', formData, {
          headers:{
            "Content-Type": "application/x-www-form-urlencoded"
          }
        })
        .then(res => {
          console.log("res = ", res.data);
          this.info = res.data;
        })
        .catch(function (error) { // 请求失败处理
          console.log(error);
        });
    },
  }
}
</script>
